package main

import "fmt"

type NumArray struct {
	Nums []int
	dps  []int
}

func Constructor(nums []int) NumArray {
	array := NumArray{Nums: nums}
	//for _,a := range nums{
	//	array.Nums = append(array.Nums, a)
	//}
	if len(nums) < 1 {
		return array
	}
	array.dps = make([]int, len(nums))
	array.dps[0] = nums[0]
	for i := 1; i < len(nums); i++ {
		array.dps[i] = array.dps[i-1] + nums[i]
	}
	return array
}

func (this *NumArray) SumRange(i int, j int) int {
	if i == j {
		return this.Nums[i]
	}
	if i > j {
		return 0
	}
	if i < 0 {
		return this.SumRange(0, j)
	}
	if j >= len(this.Nums) {
		return this.SumRange(i, len(this.Nums)-1)
	}
	if i == 0 {
		return this.dps[j]
	}
	return this.dps[j] - this.dps[i-1]
	//return this.SumRange(i+1,j) + this.Nums[i]
}

/**
 * Your NumArray object will be instantiated and called as such:
 * obj := Constructor(nums);
 * param_1 := obj.SumRange(i,j);
 */

func main() {
	array := Constructor([]int{1, 2, 3, 4, 5, 6})
	a := array.SumRange(-2, 7)
	fmt.Println(a)
}
